#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // 创建按钮和标签
//    openButton = new QPushButton("打开图片", this);
//    openButton->move(50,50);
    imageLabel = new QLabel;
    imageLabel->setMinimumSize(900,826);
    timer=new QTimer(this);

    timer->start(1000);

    connect(timer,&QTimer::timeout,this,&MainWindow::openImage);
    imageLabel->show();
}
void MainWindow::openImage()
{
    // 打开图片文件
    QString fileName = "E:\\jointImg\\src2Pic\\resultDir\\result-55.jpg";
    if (!fileName.isEmpty()) {
        QPixmap pixmap(fileName);

        if (!pixmap.isNull()) {

            QPainter painter(&pixmap);
            painter.setPen(Qt::red);
            painter.setFont(QFont("Arial", 14));
            QDateTime currentDateTime = QDateTime::currentDateTime();
            painter.drawText(320,430, currentDateTime.toString("yyyy-MM-dd HH:mm:ss")); // 在图片上添加日期时间文本
            imageLabel->setPixmap(pixmap); // 在新窗口中显示处理后的图片
            imageLabel->setScaledContents(true);//设置自适应大小

        } else {
            QMessageBox::critical(this, "错误", "无法打开图片文件");
        }
    }
}
MainWindow::~MainWindow()
{
    delete ui;
}
